package com.xhcl.web.controller.system;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import com.xhcl.common.annotation.Log;
import com.xhcl.common.enums.BusinessType;
import com.xhcl.system.domain.AccountReport;
import com.xhcl.system.domain.TGgHsdw;
import com.xhcl.system.domain.TGgKmdm;
import com.xhcl.system.domain.TSrhsAccountTemp;
import com.xhcl.system.domain.TSrhsHsxtcs;
import com.xhcl.system.domain.TSrhsKmye;
import com.xhcl.system.domain.TSrhsZybb;
import com.xhcl.system.model.TZybbAccountTemp;
import com.xhcl.system.service.ITGgHsdwService;
import com.xhcl.system.service.ITSrhsAccountTempService;
import com.xhcl.system.service.ITSrhsHsxtcsService;
import com.xhcl.system.service.ITSrhsKmyeService;
import com.xhcl.system.service.ITSrhsZybbService;
import com.xhcl.common.core.controller.BaseController;
import com.xhcl.common.core.domain.AjaxResult;
import com.xhcl.common.utils.StringUtils;
import com.xhcl.common.utils.bean.BeanUtils;
import com.xhcl.framework.uitls.poi.ExcelUtil;
import com.xhcl.framework.shiro.util.ShiroUtils;
import com.xhcl.common.core.page.TableDataInfo;

/**
 * 专用报表Controller
 * 
 * @author xhcl
 * @date 2020-09-03
 */
@Controller
@RequestMapping("/system/zybb")
public class TSrhsZybbController extends BaseController
{
    private String prefix = "system/zybb";

    @Autowired
    private ITSrhsAccountTempService tSrhsAccountTempService;
    @Autowired
    private ITSrhsHsxtcsService tSrhsHsxtcsService;
    
    @Autowired
    private ITGgHsdwService tGgHsdwService;
    
    @Autowired
    private ITSrhsZybbService tSrhsZybbService;

    @RequiresPermissions("system:zybb:view")
    @GetMapping()
    public String zybb(ModelMap mmap)
    {
    	String year=tSrhsHsxtcsService.getHsxtcsnr("year");
    	String term=tSrhsHsxtcsService.getHsxtcsnr("term");
    	List<String> ndlist=new ArrayList();
    	for (int i=0;i<5;i++) {
    		ndlist.add(String.valueOf(Integer.parseInt(year)-i));
    	}
    	mmap.put("ndlist", ndlist);
    	mmap.put("year", year);
    	List<String> yflist=new ArrayList();
    	for (int i=1;i<=12;i++) {
    		yflist.add(String.valueOf(i));
    	}
    	mmap.put("yflist", yflist);
    	mmap.put("term", term);
    	List<TSrhsZybb> zybblist=tSrhsZybbService.selectTSrhsZybbList(null);
    	mmap.put("zybblist", zybblist);
        return prefix + "/zybb";
    }
    


    /**
     * 查询专用报表列表
     */
    @RequiresPermissions("system:zybb:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TSrhsKmye srhsKmye)
    {
    	
    	Map<String,Object> map=new HashMap<String,Object>();
    	map.put("bbbh", srhsKmye.getParams().get("bbbh")==null?0:Integer.parseInt(srhsKmye.getParams().get("bbbh").toString()));
    	map.put("mxfs", srhsKmye.getParams().get("mxfs")==null?0:Integer.parseInt(srhsKmye.getParams().get("mxfs").toString()));
    	map.put("nd", srhsKmye.getNd());
    	map.put("yf", srhsKmye.getYf());
    	map.put("sdwbm", srhsKmye.getParams().get("sdwbm"));
    	map.put("edwbm", srhsKmye.getParams().get("edwbm"));
    	map.put("fs", srhsKmye.getParams().get("mxfs")==null?0:Integer.parseInt(srhsKmye.getParams().get("mxfs").toString()));
    	map.put("yefs", srhsKmye.getParams().get("yefs")==null?0:(srhsKmye.getParams().get("yefs").equals("on")?1:0));
    	List<TSrhsAccountTemp> list = tSrhsAccountTempService.selectcallZybb(map);
        return getDataTable(list);
    }

    /**
     * 导出专用报表
     */
    @RequiresPermissions("system:zybb:export")
    @Log(title = "专用报表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TSrhsKmye srhsKmye)
    {
    	Map<String,Object> map=new HashMap<String,Object>();
    	map.put("bbbh", srhsKmye.getParams().get("bbbh")==null?0:Integer.parseInt(srhsKmye.getParams().get("bbbh").toString()));
    	map.put("mxfs", srhsKmye.getParams().get("mxfs")==null?0:Integer.parseInt(srhsKmye.getParams().get("mxfs").toString()));
    	map.put("nd", srhsKmye.getNd());
    	map.put("yf", srhsKmye.getYf());
    	map.put("sdwbm", srhsKmye.getParams().get("sdwbm"));
    	map.put("edwbm", srhsKmye.getParams().get("edwbm"));
    	map.put("fs", srhsKmye.getParams().get("mxfs")==null?0:Integer.parseInt(srhsKmye.getParams().get("mxfs").toString()));
    	map.put("yefs", srhsKmye.getParams().get("yefs")==null?0:(srhsKmye.getParams().get("yefs").equals("on")?1:0));
    	List<TSrhsAccountTemp> list = tSrhsAccountTempService.selectcallZybb(map);
    	List<TZybbAccountTemp> newlist=new ArrayList<TZybbAccountTemp>();
    	list.forEach(item->{
    		TZybbAccountTemp tmp=new TZybbAccountTemp();
    		BeanUtils.copyProperties(item, tmp);
    		newlist.add(tmp);
    	});
    	
        ExcelUtil<TZybbAccountTemp> util = new ExcelUtil<TZybbAccountTemp>(TZybbAccountTemp.class);
        return util.exportExcel(newlist, "zybb");
    }

    
     
}
